package itheima02;

import utils.JDBCUtil;

import java.sql.*;
import java.util.Scanner;

/**
 * @author xxx
 * @date 2021/1/4 17:17
 * @description
 */
public class Test2 {
    public static void main(String[] args) throws SQLException {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入用户名:");
        String uname=scanner.nextLine();

        Scanner scanner1=new Scanner(System.in);
        System.out.println("请输入密码:");
        String upass=scanner1.nextLine();


        Connection connection= JDBCUtil.getConnection();
        Statement statement=connection.createStatement();

        String sql="select * from  users where uname=? and upass=?";

        PreparedStatement preparedStatement=connection.prepareStatement(sql);
        preparedStatement.setObject(1,uname);
        preparedStatement.setObject(2,upass);
        System.out.println(preparedStatement);

        ResultSet resultSet=preparedStatement.executeQuery();

        if (resultSet.next()){
            System.out.println("登陆成功");
        }else {
            System.out.println("登陆失败");
        }
        JDBCUtil.release(connection,statement,resultSet);
    }
}
